package org.istt.model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Iterator;

import org.apache.commons.lang.BooleanUtils;
import org.istt.domain.File;
import org.istt.domain.FileManagement;



public class FileBean implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String category;
	private String result;
	private String note;
	private String submiter;
	private String sender;
	private String location;
	private String inputDate;
	private String outputDate;
	private String returnDate;
	private String whoGetResult;
	private String dateGetResult;

	private String whoReceiveFileOnegate;
	private String dateReceiveFileOnegate;
	private String whoReceiveFileProcess;
	private String dateReceiveFileProcess;

	// Constructors
	/**
     * Constructs a <code>FileBean</code>
     *
     * @param inputFile the file contains all information of file
     * @param result the result of calculation overtime of file
     * @param dateReceiveFileToProcess the date that is assigned to process the file
     * @param whoReceiveFileToProcess Fullname of user that is assigned to process the file
     */
	public FileBean(File inputFile, String result, String note, String categoryName) {
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

		this.setCategory(categoryName);
		this.note = note;
		this.result = result;
		this.sender = inputFile.getContactName();
		this.submiter = inputFile.getSubmitter();
		this.location = inputFile.getLocation();
		if(inputFile.getOutputDate()!=null){
			this.outputDate = dateFormat.format(inputFile.getOutputDate().toDate());
		}
		this.inputDate = dateFormat.format(inputFile.getInputDate().toDate());
		this.whoGetResult = inputFile.getReceiver();
		if (inputFile.getDateGetResult() != null) {
			//this.dateReceiveFileOnegate = dateFormat.format(inputFile.getDateGetResult().toDate());
			this.returnDate = dateFormat.format(inputFile.getDateGetResult().toDate());
		}
		// Ngay nhan vien phong 1 cua nhan lai ho so tu phong CM
		if(inputFile.getDateCompleted()!=null && !"".equals(inputFile.getDateCompleted())){
			this.dateReceiveFileOnegate = dateFormat.format(inputFile.getDateCompleted().toDate());
		}
		
		if(inputFile.getFileManagements()!=null && inputFile.getFileManagements().size()!=0){
			for (Iterator<FileManagement> iterator = inputFile.getFileManagements().iterator(); iterator.hasNext();) {
				FileManagement fileManagement = (FileManagement) iterator.next();
				
				// Lay thong tin Nguoi nhan, Ngay nhan cua phong CM
				if(BooleanUtils.isTrue(fileManagement.getWorkflowProcess().getLineDept())){
					if(fileManagement.getReceivedDate()!=null && !"".equals(fileManagement.getReceivedDate())){
						this.dateReceiveFileProcess = dateFormat.format(fileManagement.getReceivedDate().toDate());
					}
					this.whoReceiveFileProcess = fileManagement.getApprover().getFullname();
				}
				// CASE ho so da xu ly xong
				if(inputFile.getDateCompleted()!=null && !"".equals(inputFile.getDateCompleted())){
					if(fileManagement.getWorkflowProcess().getEndProcess() != null && fileManagement.getWorkflowProcess().getEndProcess()){
						// Nguoi nhan phong 1 cua
						this.whoReceiveFileOnegate = fileManagement.getApprover().getFullname();
					}
				}
			}
		}
	}


	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getOutputDate() {
		return outputDate;
	}

	public void setOutputDate(String outputDate) {
		this.outputDate = outputDate;
	}

	public String getWhoGetResult() {
		return whoGetResult;
	}

	public void setWhoGetResult(String whoGetResult) {
		this.whoGetResult = whoGetResult;
	}

	public String getDateGetResult() {
		return dateGetResult;
	}

	public void setDateGetResult(String dateGetResult) {
		this.dateGetResult = dateGetResult;
	}

	public String getWhoReceiveFileOnegate() {
		return whoReceiveFileOnegate;
	}

	public void setWhoReceiveFileOnegate(String whoReceiveFileOnegate) {
		this.whoReceiveFileOnegate = whoReceiveFileOnegate;
	}

	public String getDateReceiveFileOnegate() {
		return dateReceiveFileOnegate;
	}

	public void setDateReceiveFileOnegate(String dateReceiveFileOnegate) {
		this.dateReceiveFileOnegate = dateReceiveFileOnegate;
	}

	public String getWhoReceiveFileProcess() {
		return whoReceiveFileProcess;
	}

	public void setWhoReceiveFileProcess(String whoReceiveFileProcess) {
		this.whoReceiveFileProcess = whoReceiveFileProcess;
	}

	public String getDateReceiveFileProcess() {
		return dateReceiveFileProcess;
	}

	public void setDateReceiveFileProcess(String dateReceiveFileProcess) {
		this.dateReceiveFileProcess = dateReceiveFileProcess;
	}

	public void setInputDate(String inputDate) {
		this.inputDate = inputDate;
	}

	public String getInputDate() {
		return inputDate;
	}

	public void setReturnDate(String returnDate) {
		this.returnDate = returnDate;
	}

	public String getReturnDate() {
		return returnDate;
	}


	public void setCategory(String category) {
		this.category = category;
	}


	public String getCategory() {
		return category;
	}


	public void setSubmiter(String submiter) {
		this.submiter = submiter;
	}


	public String getSubmiter() {
		return submiter;
	}


	public void setNote(String note) {
		this.note = note;
	}


	public String getNote() {
		return note;
	}
    
}